package com.xgame.server.dbtool;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.xgame.server.db.mapper.HeroitemMapper;
import com.xgame.server.db.model.Heroitem;
import com.xgame.server.netty.proto.Game;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

@Component
public class HeroitemCsTool {
    @Resource
    private HeroitemMapper heroitemMapper;

    //插入经验副本
    public Integer insertHeroItem(String account, String playerId, Game.HeroOneCS data) throws Exception {

        List<Game.ItemOneCs> items = data.getArmLstList();
        int length = items.size();
        Integer count = new Integer(0);
        for (int i = 0; i < length; i++) {
            Game.ItemOneCs one = items.get(i);
            Heroitem map = new Heroitem();
            map.setAccount(account);
            map.setPlayerId(playerId);
            map.setHeroId(data.getId());
            map.setGuid(one.getGuid());
            map.setItemId(one.getItemId());
            map.setNum(one.getNum());
            map.setEnhanceLv(one.getEnhanceLv());

            count += heroitemMapper.insert(map);
        }

        return count;
    }

    //删除记录
    public Integer deleteHeroItem(String account) throws Exception {
        EntityWrapper<Heroitem> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);

        return heroitemMapper.delete(userWrapper);
    }

    //查询记录
    public List<Heroitem> selectHeroItem(String account) throws Exception {
        EntityWrapper<Heroitem> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);

        return heroitemMapper.selectList(userWrapper);
    }

    //查询记录
    public List<Heroitem> selectHeroItem(String account, Integer heroid) throws Exception {
        EntityWrapper<Heroitem> userWrapper = new EntityWrapper<>();
        userWrapper.eq("account", account);
        userWrapper.eq("hero_id", heroid);

        return heroitemMapper.selectList(userWrapper);
    }

}
